package lab02.test24;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Test24 {

    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");//xxxx-xx-xx
        System.out.println("enter first time(like 19970101 information) :");
        String firsttime = sc.next();

        String str = df2.format(new Date());//得到系统时间
        int nowyear = Integer.parseInt(firsttime.substring(0, 4));//得到系统年1
        int nowmonth = Integer.parseInt(firsttime.substring(4, 6));//得到系统月1
        int nowday = Integer.parseInt(firsttime.substring(6, 8));//得到系统日1
        String datenow = nowyear + "-" + nowmonth + "-" + nowday;//计算在系统年1的生日
        java.util.Date nowdate = df2.parse(datenow);//转化字符串为日期
        long nowtime = nowdate.getTime();//得到系统1的毫秒

        System.out.println("enter second time(like 19970101 information) :");
        String secondtime = sc.next();

        int nextyear = Integer.parseInt(secondtime.substring(0, 4));//得到年2
        int nextmonth = Integer.parseInt(secondtime.substring(4, 6));//得到月2
        int nextday = Integer.parseInt(secondtime.substring(6, 8));//得到日2

        String datenext = nextyear + "-" + nextmonth + "-" + nextday;//计算在系统年2的生日
        java.util.Date nextdate = df2.parse(datenext);//转化字符串为日期
        long timenext = nextdate.getTime();//得到在系统年2的毫秒

        System.out.println(Math.toIntExact((timenext - nowtime) / 1000 / 60 / 60 / 24 ));
    }
}
